package org.boulderfoodrescue.webapp.client.events;

import org.boulderfoodrescue.webapp.shared.LoginInfo;

import com.google.gwt.event.shared.GwtEvent;

public class LoginInfoUpdatedEvent extends GwtEvent<LoginInfoUpdatedHandler>{
	private static final Type<LoginInfoUpdatedHandler> TYPE = new Type<LoginInfoUpdatedHandler>();
	private DataState dataState;
	private LoginInfo loginInfo;
	
  public LoginInfoUpdatedEvent(DataState dataState) {
  	this.dataState = dataState;
  }
  
  /**
   * Call this constructor if new loginInfo has been successfully created
   * @param loginInfo This is the login info loaded by the login info manager
   */
  public LoginInfoUpdatedEvent(LoginInfo loginInfo){
  	this.loginInfo = loginInfo;
  	this.dataState = DataState.Loaded;
  }

  public static Type<LoginInfoUpdatedHandler> getType() {
    return TYPE;
  }

  @Override
  public com.google.gwt.event.shared.GwtEvent.Type<LoginInfoUpdatedHandler> getAssociatedType() {
    return TYPE;
  }
  
	@Override
  protected void dispatch(LoginInfoUpdatedHandler handler) {
		switch(dataState)
		{
		case Loading: handler.onLoginInfoLoading();return;
		case Loaded: handler.onLoginInfoLoadSuccess(loginInfo);return;
		case Failed: handler.onLoginInfoLoadFailed();return;
		}
  }

}
